<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
  <xsl:output method="html"/>
  <xsl:template match="/ChangeLog">
    <html>
      <head>
        <title>Release Notes Generated from TFS</title>
        <style type="text/css">
          .HeaderColumnStyle
          {
          width: 566px;
          border: None;
          }
          .DataColumnStyle
          {
          border: none; width:auto;
          white-space: -moz-pre-wrap; /* Firefox */
          white-space: -pre-wrap; /* ancient Opera */
          white-space: -o-pre-wrap; /* newer Opera */
          white-space: pre-wrap; /* Chrome; W3C standard */
          word-wrap: break-word; /* IE */
          }
          .DescriptionDataColumnStyle
          {
          border: none;
          width: 850px;
          white-space: -moz-pre-wrap; /* Firefox */
          white-space: -pre-wrap; /* ancient Opera */
          white-space: -o-pre-wrap; /* newer Opera */
          white-space: pre-wrap; /* Chrome; W3C standard */
          word-wrap: break-word; /* IE */
          }
          .style1
          {
          border-style: none;
          border-color: inherit;
          border-width: medium;
          width: 60px;
          }
        </style>
      </head>
      <body>
        <h1 align="center"> TFS Change Log Report</h1>
        <table frame="box" border="3" style="width: 100%; border-bottom:#000080 outset;border-left:#000080 outset;border-top:#000080 outset;border-right:#000080 outset; text-align: left; vertical-align: middle;">
          <tr>
            <td class="HeaderColumnStyle">
              <b>
                <xsl:text>TFS Server : </xsl:text>
              </b>
              <xsl:apply-templates select="TFSServer/node()"/>
            </td>
            <td class="HeaderColumnStyle">
              <b>
                <xsl:text>Project Name : </xsl:text>
              </b>
              <xsl:apply-templates select="TFSProjectName/node()"/>
            </td>
          </tr>
          <tr>
            <td class="HeaderColumnStyle">
              <b>
                <xsl:text>Branch Location : </xsl:text>
              </b>
              <xsl:apply-templates select="TFSProjectBranchName/node()"/>
            </td>
            <td class="HeaderColumnStyle">
              <b>
                <xsl:text>Report Produced By : </xsl:text>
              </b>
              <xsl:apply-templates select="ReportProducedBy/node()"/>
            </td>
          </tr>
          <tr>
            <td class="HeaderColumnStyle">
              <b>
                <xsl:text>From Changeset : </xsl:text>
              </b>
              <xsl:apply-templates select="FromChangeSet/node()"/>
            </td>
            <td class="HeaderColumnStyle">
              <b>
                <xsl:text>To Changeset : </xsl:text>
              </b>
              <xsl:apply-templates select="ToChangeSet/node()"/>
            </td>
          </tr>
          <tr>
            <td class="HeaderColumnStyle">
              <b>
                <xsl:text>Total Number of Changesets : </xsl:text>
              </b>
              <xsl:value-of select="count(distinct-values(/ChangeLog//ChangeSet/ID))"/>
            </td>
            <td class="HeaderColumnStyle">
              <b>
                <xsl:text>Total Number of Work Items : </xsl:text>
              </b>
              <xsl:value-of select="count(distinct-values(/ChangeLog/ChangeSets//WorkItems//WorkItem/_ID))"/>
            </td>
          </tr>
          <tr>
            <td class="HeaderColumnStyle">
              <b>
                <xsl:text>Changesets with associated Work Items : </xsl:text>
              </b>
              <xsl:value-of select="count(/ChangeLog//ChangeSet[WorkItems/WorkItem/_ID[1] > 0])"/>
            </td>
            <td class="HeaderColumnStyle">
              <b>
                <xsl:text>Changesets without associated Work Items : </xsl:text>
              </b>
              <xsl:value-of select="count(distinct-values(/ChangeLog//ChangeSet/ID)) - count(/ChangeLog//ChangeSet[WorkItems/WorkItem/_ID[1] > 0])"/>
            </td>
          </tr>
          <tr>
            <td class="HeaderColumnStyle" colspan="2">
              <b>
                <xsl:text>Report Date : </xsl:text>
              </b>
              <xsl:apply-templates select="ReportDate/node()"/>
            </td>
          </tr>
        </table>
        <p/>
        <table style="border-style: none; width: 100%; height: 71px; text-align: left; vertical-align: middle; empty-cells: show;">
          <xsl:for-each select="//WorkItem[not(preceding::WorkItem/_ID=./_ID)]">
            <xsl:sort select="_WorkItemType"/>
            <xsl:sort select="_ID" order="ascending"/>
            <tr>
              <td class="style1" bgcolor="#c0c0c0">
                <b>
                  <xsl:text>Work Item ID</xsl:text>
                </b>
              </td>
              <td class="DataColumnStyle" style="width:110px;" bgcolor="#c0c0c0">
                <b>
                  <xsl:text>Work Item Type</xsl:text>
                </b>
              </td>
              <td class="DataColumnStyle" style="width:110px;" bgcolor="#c0c0c0">
                <b>
                  <xsl:text>Status</xsl:text>
                </b>
              </td>
              <td class="DataColumnStyle" style="width:auto;" bgcolor="#c0c0c0">
                <b>
                  <xsl:text>Title : </xsl:text>
                </b>
              </td>
              <td class="DataColumnStyle" style="width:110px;" bgcolor="#c0c0c0">
                <b>
                  <xsl:text>Assigned To</xsl:text>
                </b>
              </td>
            </tr>
            <tr>
              <td class="style1">
                <xsl:apply-templates select="_ID"/>
              </td>
              <td class="DataColumnStyle" style="width:110px;">
                <xsl:apply-templates select="_WorkItemType"/>
              </td>
              <td class="DataColumnStyle" style="width:110px;">
                <xsl:apply-templates select="_State"/>
              </td>
              <td class="DataColumnStyle" style="width:auto;">
                <xsl:apply-templates select="_Title"/>
              </td>
              <td class="DataColumnStyle" style="width:110px;">
                <xsl:apply-templates select="_AssignedTo"/>
              </td>
            </tr>
            <tr>
              <td class="DataColumnStyle" colspan="5" bgcolor="#c0c0c0" style="margin-bottom: 1px;/>">
                <b>
                  <p style="margin-bottom: 1px;">
                    <xsl:text>Description : </xsl:text>
                  </p>
                  <p style="margin-top:1px;"/>
                </b>
              </td>
            </tr>
            <tr>
              <td class="DescriptionDataColumnStyle" colspan="5" style="margin-bottom: 1px;/>">
                <pre>
                  <xsl:value-of select="_Description" disable-output-escaping="no"/>
                </pre>
              </td>
            </tr>
            <xsl:if test="exists(_10Principles)">
              <tr>
                <td class="DataColumnStyle" colspan="5" bgcolor="#c0c0c0" style="margin-bottom: 1px;/>">
                  <b>
                    <p style="margin-bottom: 1px;">
                      <xsl:text>10 Principles : </xsl:text>
                    </p>
                    <p style="margin-top:1px;"/>
                  </b>
                </td>
              </tr>
              <tr>
                <td class="DataColumnStyle" colspan="5" style="margin-bottom: 1px;">
                  <pre>
                    <xsl:value-of select="_10Principles" disable-output-escaping="yes"/>
                  </pre>
                </td>
              </tr>
            </xsl:if>
            <tr>
              <td colspan="5" align="right">
                <hr/>
              </td>
            </tr>
            <!--						<p><xsl:value-of select="_ID[not(.=preceding-sibling::_ID)] "/></p>-->
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
